import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/config/yt_theme.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///修理厂选择经营模式
class RepairSelectManage extends StatefulWidget {
  @override
  _RepairSelectManageState createState() => _RepairSelectManageState();
}

class _RepairSelectManageState extends State<RepairSelectManage> {
  List<String> _storeType = ["旗舰店", "认证店"];
  int _checkIndex = 0; //选中店铺类型

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () {
        //输入框失焦
        FocusScope.of(context).requestFocus(FocusNode());
      },
      child: Scaffold(
          backgroundColor: Colors.white,
          appBar: noTitleBar(context),
          body: SingleChildScrollView(
            child: Container(
              margin: EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    margin: EdgeInsets.only(top: setWidth(23)),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          child: Text(
                            "选择经营模式",
                            style: TextStyle(
                                color: Color(0xff321212),
                                fontSize: setSp(21),
                                fontWeight: FontWeight.w600),
                          ),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: setWidth(3)),
                          child: Text(
                            "向车主介绍一下自己吧",
                            style: TextStyle(
                              color: Color(0xff989898),
                              fontSize: setSp(12),
                            ),
                          ),
                        ),
                        SizedBox(
                          height: setWidth(35),
                        )
                      ],
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(top: setWidth(3)),
                    child: Text(
                      "经营模式",
                      style: TextStyle(
                          color: YTTheme.theme,
                          fontSize: setSp(15),
                          fontWeight: FontWeight.w600),
                    ),
                  ),
                  SizedBox(
                    height: setWidth(14),
                  ),
                  //店铺类型
                  Container(
                    decoration: BoxDecoration(
                        border: Border(
                      bottom: BorderSide(
                        color: Color(0xffF0F0F0),
                        width: 0.5,
                      ),
                    )),
                    padding: EdgeInsets.only(
                        top: setWidth(15), bottom: setWidth(15)),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          child: Text(
                            "店铺类型",
                            style: TextStyle(
                                color: Color(0xff321212), fontSize: setSp(15)),
                          ),
                        ),
                        Row(
                          children: _storeType
                              .asMap()
                              .map((index, value) {
                                return MapEntry(
                                    index,
                                    GestureDetector(
                                        onTap: () {
                                          if (index == 0) {
                                            _customDialog(context,
                                                title: "普通商家只能注册认证店");
                                          } else {
                                            _customDialog(context,
                                                title:
                                                    "经营旗舰店请联系电话：13030020202");
                                          }
                                          setState(() {
                                            _checkIndex = index;
                                          });
                                        },
                                        child: _selectTypeItem(
                                            index, value, _checkIndex)));
                              })
                              .values
                              .toList(),
                        )
                      ],
                    ),
                  ),
                  //经营类目
                  _selectManageContent(
                      title: "经营类目",
                      content: "奥迪，宝马，奔驰，劳斯莱斯",
                      select: () {
                        urlPush(context, "yuntu://select_labor_hour");
                        print("点击筛选");
                      }),

                  SizedBox(
                    height: setWidth(100),
                  )
                ],
              ),
            ),
          ),
          //提交
          bottomSheet: confirmButton(
              title: "提交审核",
              voidCallback: () {
                urlPush(context, "yuntu://add_to_complete");
              })),
    );
  }

  //选择类型
  Widget _selectTypeItem(int index, String value, int check) {
    return Container(
      margin: EdgeInsets.only(left: setWidth(10)),
      decoration: BoxDecoration(
          color: _checkIndex == index ? Color(0xffF1F9F5) : Color(0xffFFFFFF),
          borderRadius: BorderRadius.circular(2),
          border: Border.all(
              color:
                  _checkIndex == index ? Color(0xffF1F9F5) : Color(0xffF0F0F0),
              width: setWidth(0.5))),
      padding: EdgeInsets.only(
          top: setWidth(8),
          bottom: setWidth(8),
          left: setWidth(17),
          right: setWidth(17)),
      child: Text(
        value,
        style: TextStyle(
            color: _checkIndex == index ? YTTheme.theme : Color(0xff989898),
            fontSize: setSp(14)),
      ),
    );
  }

  //选择经营内容
  Container _selectManageContent(
      {String title, String content, Function select}) {
    return Container(
      decoration: BoxDecoration(
          border: Border(
        bottom: BorderSide(
          color: Color(0xffF0F0F0),
          width: 0.5,
        ),
      )),
      padding: EdgeInsets.only(top: setWidth(23), bottom: setWidth(23)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Container(
                child: Text(
                  title,
                  style: TextStyle(
                    color: Color(0xff323232),
                    fontSize: setSp(15),
                  ),
                ),
              ),
              InkWell(
                onTap: () => select(),
                child: Container(
                  height: setWidth(18),
                  width: setWidth(18),
                  child: Image.asset(
                    "assets/images/add_type.png",
                    fit: BoxFit.cover,
                    color: YTTheme.theme,
                  ),
                ),
              )
            ],
          ),
          SizedBox(
            height: setWidth(26),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            children: [
              Container(
                child: Text(
                  content,
                  style: TextStyle(
                    color: Color(0xff323232),
                    fontSize: setSp(14),
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  ///提示弹窗
  _customDialog(BuildContext context, {String title}) {
    showDialog<Null>(
      context: context,
      builder: (BuildContext context) {
        return new AlertDialog(
          backgroundColor: Colors.white,
          titlePadding: EdgeInsets.only(
              top: setWidth(24), left: setWidth(25), right: setWidth(25)),
          contentPadding: EdgeInsets.all(0),
          shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(10))),
          title: Text(
            title,
            style: TextStyle(color: Color(0xff323232), fontSize: setSp(15)),
          ),
          content: Container(
            height: setWidth(84),
          ),
          actions: [
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.pop(context);
              },
              child: Container(
                child: Text(
                  "取消",
                  style: TextStyle(color: YTTheme.theme, fontSize: setSp(15)),
                ),
                padding: EdgeInsets.only(bottom: setWidth(10)),
              ),
            ),
            SizedBox(
              width: setWidth(34),
            ),
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.pop(context);
              },
              child: Container(
                child: Text(
                  "确定",
                  style: TextStyle(color: YTTheme.theme, fontSize: setSp(15)),
                ),
                padding:
                    EdgeInsets.only(right: setWidth(24), bottom: setWidth(10)),
              ),
            )
          ],
        );
      },
    );
  }
}
